<template>
  <div class="detail-nav-bar">
    <nav-bar>
      <div slot="left" class="back" @click="backClick">
        <img src="~assets/img/common/back.svg" alt="" />
      </div>
      <div slot="center" class="title">
        <div
          v-for="(item, index) in titles"
          :key="index"
          class="title-item"
          :class="{active: currentIndex === index}"
          @click="titleClick(index)"
        >
          {{ item }}
        </div>
      </div>
    </nav-bar>
  </div>
</template>
<script>
import NavBar from "components/common/navBar/NavBar";
export default {
  name: "detail-nav-bar",
  components: {
    NavBar,
  },
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0,
    };
  },
  methods: {
    backClick() {
      this.$router.go(-1);
    },
    titleClick(index){
      this.currentIndex = index;
      this.$emit('titleClick', this.currentIndex);
    }
  },
};
</script>
<style lang="scss" scoped>
.detail-nav-bar{
  border-bottom: 1px solid #e5e5e5;
}
.title {
  display: flex;
  font-size: 14px;
}

.title-item {
  flex: 1;
}
.active {
  color: var(--color-high-text);
}
.back{
  line-height: 44px;
}
.back img {
  width: 20px;
}
</style>
